package com.example.demo.msg.netty.client;

import com.example.demo.msg.netty.common.IMconfig;
import com.example.demo.msg.netty.common.Imessage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class ClientHandler  extends ChannelInboundHandlerAdapter implements IMconfig {

    private ChannelHandlerContext ctx;

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {

        System.out.println("成功连接服务器");


    }


    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        Imessage m = (Imessage)msg;
        System.out.println(m.getUid() + ":" + m.getMsg());
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        System.err.println("与服务器断开连接:"+cause.getMessage());
        ctx.close();
    }
}